package com.mcptt.db;

import com.mcptt.db.model.AddrInfo;

public class DbConst {
	public static final String AUTHORITY = "com.mcptt.db";
	public static final String BASE_DIR_TYPE = "vnd.android.cursor.dir/vnd.csipsimple";
	public static final String BASE_ITEM_TYPE = "vnd.android.cursor.item/vnd.csipsimple";
	public static final String _ID = "_id";

	public static final String Table_GroupAddress = "group_address";
	public static final String COL_AddrId = "addrId";
//	public static final String COL_McId = "mcId";
	public static final String COL_Type = "type";
	public static final String COL_Name = "name";
	public static final String COL_McpttId = "mcpttId";
	public static final String COL_McvideoId = "mcvideoId";
	public static final String COL_McdataId = "mcdataId";
	public static final String COL_Attr = "attr";

	public static final String Table_Address = "address";
	public static final String COL_GroupId = "groupId";

	public static final String View_AddressList = "address_view";

	//	public static final String COL_ImageId = "imageId";

	public static final String Table_Camera = "camera";
	public static final String COL_Ip = "ip";
	public static final String COL_UserName = "userName";
	public static final String COL_Pwd = "pwd";

	public static final String Table_LoginState = "login";
	public static final String COL_UserId = "userId";
	public static final String COL_State  = "state";
	//鍘嗗彶浼氳瘽琛�
	public static final String Table_History = "history";
	public static final String Test_Table = "test";

	//    public static final String COL_ReceiverUId  = "receiverUId";
	public static final String COL_ConversationId = "conversationId";
	public static final String COL_MsgId = "msgId";
	public static final String COL_PeerType = "peerType";
	public static final String COL_PeerAddrId = "peerId";
	public static final String COL_PeerName = "peerName";
	public static final String COL_LastSenderType = "lastSenderType";
	public static final String COL_LastSenderId = "lastSenderId";
	public static final String COL_LastSenderName = "lastSenderName";
	public static final String COL_LastMsgType      = "lastMsgType";
	public static final String COL_LastMsgContent      = "lastMsgContent";
	public static final String COL_LastMsgDate      = "lastMsgDate";
	public static final String COL_UnreadCount        = "unreadCount";
//	public static final String COL_Affiliation        = "affiliation";

	public static final String Table_Session = "session";
	public static final String COL_Content = "content";
	public static final String COL_MetaData = "metaData";
	public static final String COL_Size = "size";
	public static final String COL_ContentType = "contentType";
	public static final String COL_LocalPath = "localPath";
	public static final String COL_Date = "date";
	public static final String COL_MsgType = "msgType";
	public static final String COL_Direction  = "direction";
	public static final String COL_DispositionReqType  = "dispositionReqType";
	public static final String COL_Status  = "status";
	public static final String COL_PsiControl  = "psiControl";

	public static final String Table_Map_Point = "map_point";
	public static final String COL_SenderId = "senderId";
	public static final String COL_IsSendRequest = "isSendRequest";
	public static final String COL_Lattitude = "lattitude";
	public static final String COL_Longitude = "longitude";
	public static final String COL_Altitude = "altitude";
	public static final String COL_Time = "time";
	/*public static final String COL_Last_Time = "last_time";*/
	public static final String COL_Loc_Info = "location_info";
	public static final String COL_Loc_Type = "location_type";
	public static final String Location_Track_Table = "location_track";
	public static final String COL_Valid = "location_valid";

	//閫氳褰曡〃
	public static final String Table_Config = "config";
	public static final String COL_FileName = "fileName";
	public static final String COL_ETag = "eTag"; 
	public static final String COL_ConfigContent = "content";

	//閫氳褰曡〃
	public static final String Table_Group_Config = "group_config";
	public static final String COL_GroupName = "groupName";

	//缇ょ粍鎴愬憳琛�
	public static final String TABLE_MEMBER = "member";
	public static final String COL_MEMBER_GROUP_NUM      = "gnum";
	public static final String COL_MEMBER_NUM      = "NUM";
	public static final String COL_MEMBER_NAME     = "name";
	public static final String COL_MEMBER_PRIORITY     = "priority";
	public static final String COL_MEMBER_STATUS     = "status";

	public static final String Table_Session_Group_Status = "session_group_status";
//	public static final String COL_FileName = "fileName";
//	public static final String COL_ETag = "eTag";
//	public static final String COL_ConfigContent = "content";

	protected final static String TABLE_CONFIG_CREATE =  "CREATE TABLE IF NOT EXISTS "
			+ DbConst.Table_Config
			+"("
			+ DbConst._ID	            + " INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ DbConst.COL_FileName	 			+ " text,"
			+ DbConst.COL_ETag 			+ " text,"
			+ DbConst.COL_ConfigContent 		+ " text,"
			+ DbConst.COL_Date 		+ " text)";

	protected final static String TABLE_GROUP_CONFIG_CREATE =  "CREATE TABLE IF NOT EXISTS "
			+ DbConst.Table_Group_Config
			+"("
			+ DbConst._ID	            + " INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ DbConst.COL_GroupName	 			+ " text,"
			+ DbConst.COL_ETag 			+ " text,"
			+ DbConst.COL_ConfigContent 		+ " text,"
			+ DbConst.COL_Date 		+ " text)";

	protected final static String TABLE_ADDRESS_CREATE =  "CREATE TABLE IF NOT EXISTS "
			+ DbConst.Table_Address
			+"("
			+ DbConst._ID	 			+ " INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ DbConst.COL_Type 		    + " INTEGER,"
			+ DbConst.COL_AddrId + " text,"
			+ DbConst.COL_Name 			+ " text,"
			+ DbConst.COL_McpttId 		+ " text,"
			+ DbConst.COL_McvideoId 	+ " text,"
			+ DbConst.COL_McdataId 		+ " text,"
//			+ DbConst.COL_GroupId 		+ " text,"
			+ DbConst.COL_Attr 			+ " INTEGER)";

	protected final static String TABLE_GROUP_ADDRESS_CREATE =  "CREATE TABLE IF NOT EXISTS "
			+ DbConst.Table_GroupAddress
			+"("
			+ DbConst._ID	 			+ " INTEGER PRIMARY KEY AUTOINCREMENT,"
			//		+ DbConst.COL_UID 			+ " text, "
			+ DbConst.COL_Type 		    + " INTEGER,"
			+ DbConst.COL_AddrId + " text,"
			+ DbConst.COL_Name 			+ " text,"
			+ DbConst.COL_GroupId 		+ " text,"
			+ DbConst.COL_Attr 			+ " INTEGER)";

	protected final static String TABLE_MEMBER_ADDRESS_CREATE =  "CREATE TABLE IF NOT EXISTS "
			+ DbConst.TABLE_MEMBER
			+"("
			+ DbConst._ID	 			+ " INTEGER PRIMARY KEY AUTOINCREMENT,"
			//		+ DbConst.COL_UID 			+ " text, "
			+ DbConst.COL_Type 		    + " INTEGER,"
			+ DbConst.COL_AddrId + " text,"
			+ DbConst.COL_Name 			+ " text,"
			+ DbConst.COL_GroupId 		+ " text,"
			+ DbConst.COL_MEMBER_NUM 		+ " text,"
			+ DbConst.COL_Attr 			+ " INTEGER)";

//	protected final static String TABLE_MEMBER_ADDRESS_CREATE =  "CREATE TABLE IF NOT EXISTS "
//			+ DbConst.TABLE_MEMBER
//			+"("
//			+ DbConst._ID	 			+ " INTEGER PRIMARY KEY AUTOINCREMENT,"
//			//		+ DbConst.COL_UID 			+ " text, "
//			+ DbConst.COL_Type 		    + " INTEGER,"
//			+ DbConst.COL_AddrId + " text,"
//			+ DbConst.COL_Name 			+ " text,"
//			+ DbConst.COL_GroupId 		+ " text,"
//			+ DbConst.COL_MEMBER_NUM 		+ " text,"
//			+ DbConst.COL_Attr 			+ " INTEGER)";

	protected final static String VIEW_ADDRESS_CREATE =  "CREATE VIEW "
			+ DbConst.View_AddressList
			+" as select "
			+ DbConst.COL_Type 		    + ","
			+ DbConst.COL_Name 			+ ","
			+ DbConst.COL_AddrId + ","
			+ DbConst.COL_Attr
			+ " from " + DbConst.Table_GroupAddress
			+" union all select distinct "
			+ DbConst.COL_Type 		    + ","
			+ DbConst.COL_Name 			+ ","
			+ DbConst.COL_AddrId + ","
			+ DbConst.COL_Attr
			+ " from " + DbConst.Table_Address
			+ " order by "+ DbConst.COL_Type + " ASC";

	protected final static String TABLE_LOGIN_CREATE =  "CREATE TABLE IF NOT EXISTS "
			+ DbConst.Table_LoginState
			+"("
			+ DbConst._ID	            + " INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ DbConst.COL_UserId 		+ " text,"
			+ DbConst.COL_Ip			+ " text,"
			+ DbConst.COL_State		    + " INTEGER)";
//	protected final static String TABLE_MAP_POINT_CREATE =  "CREATE TABLE IF NOT EXISTS "
//			+ DbConst.Table_Map_Point
//			+"("
//			+ DbConst._ID	 			+ " INTEGER PRIMARY KEY AUTOINCREMENT,"
//			+ DbConst.COL_SenderId 		+ " text,"
//			+ DbConst.COL_Lattitude 	+ " DOUBLE,"
//			+ DbConst.COL_Longitude     + " DOUBLE,"
//			+ DbConst.COL_Altitude 		+ " DOUBLE,"
//			+ DbConst.COL_Time			+ " LONG,"
//			+ DbConst.COL_Loc_Info		+ " text,"
//			+ DbConst.COL_Loc_Type		+ " INTEGER )";

	protected final static String TABLE_HIRSTORY_CREATE =  "CREATE TABLE IF NOT EXISTS "
			+ DbConst.Table_History
			+"("
			+ DbConst._ID	             + " INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ DbConst.COL_PeerType       + " INTEGER,"
			+ DbConst.COL_PeerAddrId + " text,"
			+ DbConst.COL_PeerName       + " text,"
			+ DbConst.COL_LastSenderId   + " text,"
			+ DbConst.COL_LastSenderName + " text,"
			+ DbConst.COL_LastMsgType    + " INTEGER,"
			+ DbConst.COL_LastMsgContent + " text,"
			+ DbConst.COL_LastMsgDate    + " DATETIME DEFAULT CURRENT_TIMESTAMP,"
			+ DbConst.COL_UnreadCount    + " text)";
//			+ DbConst.COL_Affiliation    + " INTEGER)";

	//浼氳瘽琛�
	protected final static String TABLE_SESSION_CREATE =  "CREATE TABLE IF NOT EXISTS "
			+ DbConst.Table_Session
			+"("
			+ DbConst._ID	 			 + " INTEGER PRIMARY KEY AUTOINCREMENT,"
//			+ DbConst.COL_Type 		    + " INTEGER,"//1为普通短信 2为功能号短信
			+ DbConst.COL_ConversationId + " text,"
			+ DbConst.COL_MsgId + " text,"

			+ DbConst.COL_PeerType + " INTEGER,"
			+ DbConst.COL_PeerAddrId + " text,"
			+ DbConst.COL_PeerName + " text,"
			+ DbConst.COL_LastSenderType + " INTEGER,"
			+ DbConst.COL_LastSenderId 		 + " text,"
			+ DbConst.COL_LastSenderName + " text,"

			+ DbConst.COL_MsgType 		 + " text,"
			+ DbConst.COL_Direction 	 + " INTEGER,"
			+ DbConst.COL_ContentType 		 + " INTEGER,"
			+ DbConst.COL_Content 		 + " text,"
			+ DbConst.COL_LocalPath 		 + " text,"
			+ DbConst.COL_MetaData 		 + " text,"

			+ DbConst.COL_Date 			 + " LONG,"
			+ DbConst.COL_DispositionReqType     		 + " INTEGER,"
			+ DbConst.COL_PsiControl     		 + " text,"
			+ DbConst.COL_Status     	 + " INTEGER ) ";

	protected final static String TABLE_SESSION_GROUP_STATUS_CREATE =  "CREATE TABLE IF NOT EXISTS "
			+ DbConst.Table_Session_Group_Status
			+"("
			+ DbConst._ID	 			 + " INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ DbConst.COL_ConversationId + " text,"
			+ DbConst.COL_MsgId 		 + " text,"
			+ DbConst.COL_GroupId 		 + " text,"
			+ DbConst.COL_AddrId 		 + " text,"
			+ DbConst.COL_Status     	 + " INTEGER ) ";


	protected final static String QUERY_HIRSTORY =  "SELECT distinct * FROM  "
			+ Table_History
			+" left outer join " 		+ View_AddressList
			+ " on " 					+ COL_PeerAddrId
			+ " = " 					+ COL_AddrId
			+" order by " 				+ COL_Attr + " desc"
			+" , "						+ COL_Type + " asc"
			+" , " 						+ COL_LastMsgDate + " desc";

//	protected final static String QUERY_SESSION =  "SELECT distinct * FROM  "
//			+ Table_Session
//			+" left outer join " 		+ View_AddressList
//			+ " on " 					+ COL_SenderId
//			+ " = " 					+ COL_Id
//			+ " where " 				+ COL_SenderId + " = ";

	protected final static String QUERY_SESSION_NEW =  "SELECT distinct * FROM  "
			+ Table_Session
//			+" left outer join " 		+ View_AddressList
//			+ " on " 					+ COL_SenderId
//			+ " = " 					+ COL_Id
			+ " where " 				+ COL_PeerAddrId + " = ";
	protected final static String QUERY_FUNC_SESSION_NEW =  "SELECT distinct * FROM  "
			+ Table_Session
//			+" left outer join " 		+ View_AddressList
//			+ " on " 					+ COL_SenderId
//			+ " = " 					+ COL_Id
			+ " where " 				+ COL_Type + " = ";

	protected final static String QUERY_MAPPOINT =  "SELECT distinct * FROM  "
			+ Table_Map_Point
			+" left outer join " 		+ Table_Address
			+ " on " 					+ COL_SenderId
			+ " = " 					+ COL_AddrId;

	protected final static String QUERY_LOGINSTATE = "SELECT distinct * FROM "
			+ Table_Address
			+ " left join " 			+ Table_LoginState
			+ " on " 					+ COL_UserId
			+ " = " 					+ COL_AddrId
			+ " where ";
	protected final static String QUERY_LOGINSTATE_ORDER = " order by " + COL_State + " DESC, " + COL_Type + " ASC";// + COL_Name + " ASC";

	protected final static String UPDATE_DEFAULT_GROUP =  "update " + Table_GroupAddress + " set " + COL_Attr + "= 0";
	protected final static String UPDATE_HISTORY_UNREAD =  "update " + Table_History + " set " + COL_UnreadCount + " = " + COL_UnreadCount + " + 1 where "  + COL_PeerAddrId + " = ";
	protected final static String RESET_HISTORY_UNREAD =  "update " + Table_History + " set " + COL_UnreadCount + " = 0 "  + "  where " + COL_PeerAddrId + " = ";

	public static String getMessageStatusQueryStr(String conversationId,String msgId,String groupId)
	{
		StringBuffer strBuf = new StringBuffer("select * from member,session_group_status where member.groupId = session_group_status.groupId and member.addrId = session_group_status.addrId ");
		strBuf.append("and conversationId = '").append(conversationId);
		strBuf.append("' and msgId = '").append(msgId);
		strBuf.append("' and member.groupId = '").append(groupId).append("' ");

		return strBuf.toString();
	}
//	public static String getMessageStatusQueryStr(String conversationId,String msgId,String groupId)
//	{
//		StringBuffer strBuf = new StringBuffer("select * from member,session_group_status where member.groupId = session_group_status.groupId ");
//		strBuf.append("and conversationId = '").append(conversationId);
//		strBuf.append("' and msgId = '").append(msgId);
//		strBuf.append("' and member.groupId = '").append(groupId).append("' ");
//
//		return strBuf.toString();
//	}
//	protected static String getQuerySessionSqlStr(String receiverUId)
//	{
//		String sqlStr = DbConst.QUERY_SESSION + "'" + receiverUId + "'";
//		return sqlStr;
//	}

}
